//
// Description: 223. 矩形面积
// Created by Loading on 2021/9/30.
//

#include <bits/stdc++.h>

using namespace std;

int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
    int s1 = (ax2 - ax1) * (ay2 - ay1);
    int s2 = (bx2 - bx1) * (by2 - by1);

    // 计算重叠部分宽高
    int over_width = min(ax2, bx2) - max(ax1, bx1);
    int over_height = min(ay2, by2) - max(ay1, by1);
    // 不重叠情况下，计算重叠宽高为负数
    int over_s = max(over_width, 0) * max(over_height, 0);

    return s1 + s2 - over_s;
}

int main() {
    int ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2;
    int area = computeArea(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2);
    cout << area << endl;

    return 0;
}